<?php
use yii\grid\GridView;
use backend\utils\XHtml;
use yii\helpers\Html;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '友情链接';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $this->beginBlock('content-header'); ?>
<?= $this->title . ' ' . XHtml::create('友情链接') ?>
<?php $this->endBlock(); ?>
<div class="box box-primary">
    <div class="box-body">
        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'columns' => [
                'id',
                'name',
                'sort',
                'url',
                'type',
                [
                    'label' => '链接图片',
                    'format' => ['raw'],
                    'value' => function ($model) {
                        if ($model['type'] == '图片' && $model['attach']) {
                            return Html::img(Yii::getAlias('@frontendUrl') . $model['attach'], ['width' => 80]);
                        } else {
                            return '';
                        }
                    }],
                [
                    'label' => '状态',
                    'value' => function ($model) {
                        return $model->status ? '开启' : '关闭';
                    }
                ],
                'created_at:datetime',
                ['class' => backend\utils\XColumn::className()],
            ]
        ]); ?>
    </div>
</div>